function getstudentoverview(){
    axios({
url:'/student/overview',
    })
    .then((result)=>{
        // console.log(result)
        const data=result.data.data
document.querySelector('.avgAge').innerHTML=data.avgAge
document.querySelector('.avgSalary').innerHTML=data.avgSalary
document.querySelector('.proportion').innerHTML=data.proportion
document.querySelector('.total').innerHTML=data.total
    })
}
getstudentoverview()
getstudentList()
//数据
function getstudentList(){
    axios({
       url: '/student/list',
    })
    .then((result)=>{
// console.log(result)
const list=result.data.data
// console.log('list: ', list);
rendersalary(list)
renderprovince(list)
    })
}


function rendersalary(list){
    const name=list.map((item)=>item.name)
    const salary=list.map((item)=>item.salary)
    const truesalary= list.map((item)=>item.truesalary)
    const myChart = echarts.init(document.querySelector(".line"));
const option = {
    title: {
      text: "薪资",
    },
    tooltip: {
      trigger: "axis",
    },
    legend: {},
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: name,
    },
    yAxis: {
      type: "value",
      axisLabel: {},
    },
    dataZoom: [
      {
        type: "inside",
        start: 0,
        end: 10,
      },
      {
        start: 0,
        end: 10,
      },
    ],
    series: [
      {
        name: "实际薪资",
        type: "line",
        symbol: "circle",
        data:salary,
      },
      {
        name: "期望薪资",
        type: "line",
        symbol: "circle",
        data: truesalary,
      },
    ],
  };
  // 使用刚指定的配置项和数据显示图表。
  myChart.setOption(option);}

  //饼状图
function renderprovince(list){
    console.log(list)
    const newlist=[]
    list.forEach(item => {
    const index=newlist.findIndex((element)=>element.name===item.province)
    //newlist.findIndex((element)=>element.name===item.province),的返回值是true或者false，
    //判断有没有这个元素，有就不会执行了，但是还是会返回一个下标，没用找到的下标位-1，找到的话就是有下标
    if(index===-1){
        //如果没用
        newlist.push({name:item.province,value:1})
    }else{
        //有的话再原来的备注加一
        newlist[index].value++
    }
    });

    const myChart = echarts.init(document.querySelector(".pie"));
        const option = {
        series: [
          {
            name: 'Nightingale Chart',
            type: 'pie',
            //内圈
            radius: [25, 150],
            //外圈
            center: ['50%', '50%'],
            roseType: 'area',
            itemStyle: {
              borderRadius: 8
            },
            data: newlist
          }
        ]
    };
    myChart.setOption(option);
}
const toggleBatchBtn=document.querySelector('#toggleBatchBtn')
console.log('toggleBatchBtn: ', toggleBatchBtn);
const batch=document.querySelector('#batch')
console.log('batch: ', batch);
toggleBatchBtn.addEventListener('click',function(){
    if(batch.style.display==='none'||batch.style.display===''){
        //dom.display，只能获取到行内样式的元素，获取不到选择器里面的元素
        batch.style.display='flex'
    }else{
        batch.style.display='none'
    }
})
// 根据 成绩次数来加载成绩数据
function score(index){
    axios({
        url:'/score/batch',
        method:'get',
    params:{
        batch:index
    }
    })
    .then((result)=>{
        if(result.data.code!==0){
            toastr.warning(result.data.message)
            return
        }
        console.log(result)
        const data=result.data.data
        console.log('data: ', data);
        const avgScore=data.avgScore
        console.log('avgScore: ', avgScore);
        const group=data.group
        console.log('group: ', group);
        const gt60=data.gt60
        const gt80=data.gt80
        const lt60=data.lt60
        //
        const myChart = echarts.init(document.querySelector(".barChart"));
        const option = {
            tooltip: {
              trigger: "axis",
              axisPointer: {
                type: "cross",
                crossStyle: {
                  color: "#999",
                },
              },
            },
    
            legend: {
              data: ["平均分", "低于60", "60-80", "80以上"],
            },
            xAxis: [
              {
                type: "category",
                data: group,
                axisPointer: {
                  type: "shadow",
                },
              },
            ],
            yAxis: [
              {
                type: "value",
                min: 0,
                max: 100,
                interval: 10,
                axisLabel: {
                  formatter: "{value} 分",
                },
              },
              {
                type: "value",
                min: 0,
                max: 10,
                interval: 1,
                axisLabel: {
                  formatter: "{value} 人",
                },
              },
            ],
            series: [
              {
                name: "平均分",
                type: "bar",
                tooltip: {
                  valueFormatter: function (value) {
                    return value + " ml";
                  },
                },
                data: avgScore,
              },
              {
                name: "低于60",
                yAxisIndex: 1,
                type: "bar",
                tooltip: {
                  valueFormatter: function (value) {
                    return value + " ml";
                  },
                },
                data: gt60,
              },
              {
                name: "60-80",
                yAxisIndex: 1,
                type: "bar",
                tooltip: {
                  valueFormatter: function (value) {
                    return value + " ml";
                  },
                },
                data: gt80,
              },
              {
                name: "80以上",
                yAxisIndex: 1,
                type: "bar",
                tooltip: {
                  valueFormatter: function (value) {
                    return value + " ml";
                  },
                },
                data: lt60,
              },
            ],
          };
          myChart.setOption(option);
    })
}
score(1)



batch.addEventListener('click',function(e){
if(e.target.tagName==='A'){
const index=e.target.dataset.index
console.log('index: ', index);
//点击触发获取成绩数据
score(index)

}
})

